Ext.define('designer.configWindow',{
	extend:'Ext.Window',
	controllerUrl:'',
	title:desLang.projectConfig,
	dataForm:null,
	layout:'fit',
	modal:true,
	width:400,
	height:300,
	
	initComponent:function(){
		
		this.dataForm = Ext.create('Ext.form.Panel',{
			bodyCls:'formBody',
			bodyPadding:5,
			fieldDefaults:{
		        labelAlign:'left',
				anchor:'100%',
				labelWidth:180
			},
			defaults:{
				xtype:'textfield'
			},
			items:[
			       {
			    	   name:'namespace',
			    	   fieldLabel:desLang.projectNamespace
			    	   
			       },{
			    	   name:'runnamespace',
			    	   fieldLabel:desLang.projectRunNamespace
			       }
			]
		});
		
		this.items = [this.dataForm];		
		this.buttons = [
 	       {
 	    	   text:desLang.cancel,
 	    	   scope:this,
 	    	   handler:this.close
 	       },{
 	    	   text:desLang.save,
 	    	   scope:this,
 	    	   handler:this.saveAction
 		   }           
		];
		
		this.callParent(arguments);	
		this.addEvents(
	            /**
	             * @event dataSaved
	             */
	           'dataSaved'
	    ); 
		
		this.dataForm.load({
			url:this.controllerUrl +  '/project/loadconfig',
			scope:this,
			failure:function(form, action){
				Ext.Msg.alert(appLang.MESSAGE, desLang.cantLoad);
				this.close();
			}
		});
	},
	saveAction:function()
	{
		 var me = this;
		this.dataForm.getForm().submit({
			clientValidation: true,
			waitMsg: appLang.SAVING,
			method:'post',
			scope:this,
			url:this.controllerUrl +  '/project/setconfig',
			success: function(form, action) {	
   		 		if(!action.result.success){
   		 			Ext.Msg.alert(appLang.MESSAGE, action.result.msg);
   		 		} else{
   		 			me.fireEvent('dataSaved');		 
   		 			me.close();
   		 		}
   	        },
   	        failure: app.formFailure
   	    });
	}
});